package com.xinqi.modules.sys.gpt.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.log.asynclog.annotation.AsyncLog;
import com.xinqi.common.log.asynclog.enums.AsyncOperaType;
import com.xinqi.common.log.asynclog.enums.AsyncType;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.group.dto.rsp.ShareSelectResultDTO;
import com.xinqi.modules.sys.gpt.dto.req.ShareLogQueryDTO;
import com.xinqi.modules.sys.gpt.dto.rsp.ShareLogResultDTO;
import com.xinqi.modules.sys.gpt.service.ShareLogService;
import com.xinqi.modules.user.user.dto.req.UserShareRegisterDTO;
import com.xinqi.modules.user.user.dto.rsp.UserResultDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * APP -- 用户分享注册记录
 *
 * @author: yyzhen
 * @date: 2023/05/23
 */
@RestController
@RequestMapping("/app/share-log")
@RequiredArgsConstructor
public class ShareLogAppController {
    private final ShareLogService shareLogService;

    @Operation(summary = "邀请链接-不区分微信、QQ")
    @PostMapping("/share")
    public R<ShareSelectResultDTO> share() {
        return R.data(shareLogService.getSharePersonalInfo(LoginHelper.getUserId()));
    }

    @AsyncLog(title = "用户注册--新奇问问邀请链接", asyncType = AsyncType.REGISTER, operatorType = AsyncOperaType.USER_REGISTER)
    @Operation(summary = "邀请链接-注册")
    @PostMapping("/register")
    public R<UserResultDTO> shareRegister(@Validated @RequestBody UserShareRegisterDTO registerDto) {
        return R.ok(MessageUtils.message("gpt.share.register.success"), shareLogService.shareRegister(registerDto));
    }

    @Operation(summary = "用户分享注册记录-分页")
    @GetMapping("/page")
    public R<PageInfo<ShareLogResultDTO>> page(@ParameterObject ShareLogQueryDTO dto) {
        dto.setOperationUserId(LoginHelper.getUserId());
        PageInfo<ShareLogResultDTO> page = shareLogService.page(dto, dto);
        return R.data(page);
    }

}
